import {I18Parse,CommonLang} from '@lowcode/jpaas-base-lib';

/**
 * 日历视图方法
 */

import FormSolutionApi from '@/common/api/form/formSolution'

export default {
    data() {
        return {
            dialogBox: {},
        }
    },
    created() {
        const file = import.meta.globEager(`/src/assets/js/dialogBox.js`);
        this.dialogBox = file["/src/assets/js/dialogBox.js"].default;
    },
    methods: {
        openCalendarForm(obj) {
            if (!obj.alias) {
                return;
            }
            if (!obj.readOnly) {
                obj.readOnly = false;
            }
            var self = this;
            let config = {
                title: obj.title,
                curVm: self,
                max:true,
                data: {
                    alias: obj.alias,
                    pkId: obj.pkId,
                    readOnly: obj.readOnly,
                    parent: obj.parent,
                    //将表单映射数据提交到表单数据。
                    setInitData(data) {
                        if (self.formdata) {
                            Object.assign(data, self.formdata);
                        }
                        return data;
                    },
                    closeOnSave:true
                },
                shade: true,
                urlType: obj.urlType,//用于区分表单按钮的打开方式
            }
            //是否全屏
            if(this.calendarView.isMax=="NO"){
                var width=this.calendarView.width?this.calendarView.width+"px":"650px";
                var height=this.calendarView.height?this.calendarView.height+"px":"350px";
                config.widthHeight= [width, height];
            }else {
                config.max=true;
            }
            this.dialogBox.showForm(config, function (action) {
                self.onRefresh();
            });
        },
        onAdd() {//增加
            let _obj = {
                title: this.calendarView.name + '--'+I18Parse.getI18Val(CommonLang,'rxList.newBtn','添加') ,
                alias: this.calendarView.formAddAlias ? this.calendarView.formAddAlias : this.calendarView.formAlias,
                urlType: 'Add'
            }
            this.openCalendarForm(_obj);
        },
        onEdit(data) {//編輯
            let _obj = {
                title: this.calendarView.name + '--'+I18Parse.getI18Val(CommonLang,'rxList.editBtn','编辑'),
                alias: this.calendarView.formAlias,
                pkId: data.pkId,
                urlType: 'Edit'
            }
            this.openCalendarForm(_obj);
        },
        onRemove(data) {
            let self_ = this;
            this.$confirm({
                title: I18Parse.getI18Val(CommonLang,'rxMsa.actionTips','操作提示'),
                zIndex: 20000,
                content: I18Parse.getI18Val(CommonLang,'rxMsa.delInfo','您确定需要删除选中的记录吗？'),
                okText: I18Parse.getI18Val(CommonLang,'rxForm.ackBtn','确认'),
                cancelText: I18Parse.getI18Val(CommonLang,'rxForm.cancelBtn','取消'),
                onOk() {
                    FormSolutionApi.removeById({alias: self_.calendarView.formAlias, id: data.pkId}).then(res => {
                        self_.onRefresh();
                    });
                }
            })
        },
        onDetail(data) {
            let _obj = {
                title: this.calendarView.name + '--'+I18Parse.getI18Val(CommonLang,'rxList.detailBtn','明细'),
                alias: this.calendarView.formDetailAlias ? this.calendarView.formDetailAlias : this.calendarView.formAlias,
                pkId: data.pkId,
                readOnly: true,
                urlType: 'Details'
            }
            this.openCalendarForm(_obj);
        },
        onRefresh(){
            this.loadData(this.calendarView.key);
        }
    }
}
